﻿CREATE PROCEDURE [dbo].[wikiCategories_validate]
    @wikiCategoryId int = 0,
    @name nvarchar(256) = null
AS
BEGIN
    IF(@wikiCategoryId = 0)
        RETURN CASE
            WHEN EXISTS (
                SELECT WikiCategories.CategoryId
                FROM WikiCategories
                WHERE WikiCategories.Name = @name)
                THEN 0
                ELSE 1
        END
    ELSE 
        RETURN CASE 
            WHEN EXISTS(
                SELECT WikiCategories.CategoryId
                FROM WikiCategories
                WHERE WikiCategories.Name = @name AND WikiCategories.CategoryId !=@wikiCategoryId)
                THEN 0
                ELSE 1
        END
END
